package com.woniuxy.exam.controller;

import com.woniuxy.exam.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件操作接口")
@RestController
@RequestMapping(value = "/file")
public class FileUploadController {
    @Autowired
    private IFileService fileService;
    // @RequestPart: 解决swagger无法测试文件上传选择文件的问题。
    @PostMapping("/upload")
    @ApiOperation("上传头像")
    public String uploadFile(@RequestPart MultipartFile file) {
        // 文件上传，返回阿里云上传的文件地址
        String url = fileService.uploadFile(file);
        return url;
    }
}